package com.gestocasa.view.views.helper;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import com.gestocasa.model.Configuration;

public class ConfigurationsCellRenderer extends JLabel implements ListCellRenderer {
	
	public ConfigurationsCellRenderer() {
		setOpaque(true);
	}

	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		if(value instanceof Configuration) {
			setText(((Configuration)value).getName());
		}
		else {
			if(value != null) {
				setText(value.toString());
			}
		}

	    if (isSelected) {
	    	setBackground(list.getSelectionBackground());
	    	setForeground(list.getSelectionForeground());
	    } 
	    else {
	    	setBackground(list.getBackground());
	    	setForeground(list.getForeground());
	    }
	    return this;
	}
}
